<?php if(!$error){ ?>
<div class="companies form">
<?php
    echo $this->Form->create('Company', array('id' => 'form_edit_company'));
    echo $this->Form->hidden('id', array('value' => $company['Company']['id']));
    echo $this->Form->hidden('clCompanyId', array('value' => $clCompanyId));
?>
	<fieldset>
 		<legend><?php printf(__('Setup new %s', true), __('Company', true)); ?></legend>
	<?php


		echo $this->Form->input('name', array('value' => $company['Company']['name'], 'label' => __('Company Name:<em class="required_field">(required)</em><em id="cp_name_error"></em>', true), 'id' => 'company_name', 'after' => '<em class="company_slug">'.FULL_BASE_URL.'/company/<span id="company_link">'.$company['Company']['guid'].'</span></em>'));

		echo $this->Form->hidden('slug', array('id' => 'slug', 'value' => $company['Company']['guid']));

                echo $this->Form->input('house_number', array('id' => 'house_number', 'label' => __('House Number:<em class="required_field">(required)</em><em id="cp_house_number_error"></em>', true), 'value' => $company['Company']['house_number']));
                echo $this->Form->input('street', array('value' => $company['Company']['street'], 'id' => 'comany_street','label' => __('Street:<em class="required_field">(required)</em><em id="cp_street_error"></em>', true)));
                echo $this->Form->input('city', array('value' => $company['Company']['city'], 'label' => 'City/Province:'));
                echo $this->Form->input('country_id', array('value' => $company['Company']['country_id'], 'label' => __('Country:', true)));
                echo $this->Form->input('tel', array('value' => $company['Company']['tel'], 'label' => __('Tel:', true)));
            echo $this->Form->input('email', array('value' => $company['Company']['email'] , 'id' => 'cp_email', 'label' => __('Email:<em id="cp_email_error"></em>', true)));

       ?>
      </fieldset>
      <fieldset>
          <legend><?php __('Classification') ?></legend>
          <?php
          echo $this->Html->tag('label', __('Classification:', true), array('for' => 'classification'));
          ?>
          <select id="classification" name="data[Company][classification]">
              <option value="0"><?php __('Select a classification') ?></option>
              <?php

                foreach($classifications as $cl){
                    if($parentId == $cl['Classification']['id']){
                    ?>
                        <option value="<?php echo $cl['Classification']['id']?>" selected="selected"><?php echo $cl['Classification']['name'] ?></option>
                    <?php
                    }else{
                    ?>
                        <option value="<?php echo $cl['Classification']['id']?>"><?php echo $cl['Classification']['name'] ?></option>
                    <?php
                    }
                }
              ?>
          </select>
          <em id="childClassification" class="childClassify">
              <?php if(!empty($clasChild)){?>
              <select id="children" name="data[Company][children]">
                  <?php
                  foreach($clasChild as $ch){
                      if($childId == $ch['Classification']['id']){
                        ?>
                            <option value="<?php echo $ch['Classification']['id']?>" selected="selected"><?php echo $ch['Classification']['name'] ?></option>
                        <?php
                        }else{
                        ?>
                            <option value="<?php echo $ch['Classification']['id']?>"><?php echo $ch['Classification']['name'] ?></option>
                        <?php
                        }
                  }
                   ?>
              </select>
              <?php } ?>
         </em>
      </fieldset>
      <fieldset>
          <legend><?php __('Aditional Information') ?></legend>
       <?php
            
            echo $this->Form->input('phone', array('value' => $company['Company']['phone'], 'label' => __('Mobile Phone:', true)));
            echo $this->Form->input('fax', array('value' => $company['Company']['fax'], 'label' => __('Fax:', true)));
            echo $this->Form->input('pobox', array('value' => $company['Company']['pobox'], 'label' => __('P.O.BOX:', true)));
            echo $this->Form->input('website', array('value' => $company['Company']['website'] , 'id' => 'cp_website', 'label' => __('Website:', true)));
            echo $this->Form->input('description', array('value' => $company['Company']['description'], 'label' => __('Description:', true)));
	?>
      </fieldset>

<?php
    echo $this->Form->button(__('Save Change', true), array('class' => 'button', 'type' => 'button', 'id' => 'save_change'));
    echo $this->Html->link(__('Cancel', true), $company['Company']['slug'], array('class' => 'cancel_link'));
    echo $this->Form->end();
 ?>
<?php echo $this->Html->script('validate')?>
<?php

        $this->Js->get('#company_name');
	$this->Js->event('keyup', 'companySlug("'.$userId.'","#company_name","#company_link")');
       
        #live check email
        $this->Js->get('#cp_email');
        $this->Js->event('blur', 'checkEmail("#cp_email", "#cp_email_error", "'.__('Invalid Email!', true).'")');

        #get Child of classification
        $this->Js->get('#classification');
        $this->Js->event('change', 'updateChild("#classification","#childClassification","'.$this->base.'/classifications/childClassification/")');

         #submit change company
        $this->Js->get('#save_change');
        $this->Js->event('click', 'submitCompany()');

?>
<script type="text/javascript">
    function submitCompany(){
        if(companyRequiredField('#company_name', '#cp_name_error', '<?php __("Company name is required.") ?>') == false){
            return false;
        }
        if(companyRequiredField('#house_number', '#cp_house_number_error', '<?php __("Hose number is required.") ?>') == false){
            return false;
        }
        if(companyRequiredField('#comany_street', '#cp_street_error', '<?php __("Street is required.") ?>') == false){
            return false;
        }
        if(checkEmail('#cp_email', '#cp_email_error', '<?php __("Invalid Email!", true); ?>'))

    $('#form_edit_company').submit();
    }
</script>
</div>
<?php

} else {
  $message = sprintf(__('You do not have permission to change %s. ', true), $company['Company']['name']);
  $link = $this->Html->link(__('Back', true), $company['Company']['slug'], array('title' => sprintf(__('Back to %s', true), $company['Company']['name'])));

  echo $this->Html->tag('div', $this->Html->tag('span','', array('class' => 'ui-icon ui-icon-alert')). $message . $link , array('class' => 'ui-state-error ui-corner-all', 'id' => 'alert_message'));
}
?>

